package com.cy.scrollviewandrecyclerview;

import android.os.Bundle;
import android.os.Handler;
import android.widget.TableLayout;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.cy.scrollviewandrecyclerview.common.viewpager.ViewPagerAdapter;
import com.cy.scrollviewandrecyclerview.customview.HeaderScrollDisabledRecyclerView;
import com.cy.scrollviewandrecyclerview.fragment.RecyclerViewFragment;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.combo_top_view)
    HeaderScrollDisabledRecyclerView comboTopView;
    @BindView(R.id.tabLayout)
    com.google.android.material.tabs.TabLayout tabLayout;
    @BindView(R.id.viewpager_view)
    ViewPager2 viewpagerView;
    @BindView(R.id.SmartRefreshLayout)
    com.scwang.smart.refresh.layout.SmartRefreshLayout SmartRefreshLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        ViewPagerAdapter pagerAdapter = new ViewPagerAdapter(this, getPageFragments());
        viewpagerView.setAdapter(pagerAdapter);
        final String[] labels = new String[]{"linear", "scroll", "recycler"};
        new TabLayoutMediator(tabLayout, viewpagerView, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(labels[position]);
            }
        }).attach();
        SmartRefreshLayout.setEnableRefresh(false);
        SmartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                SmartRefreshLayout.finishRefresh();
            }
        });
    }

    private List<Fragment> getPageFragments() {
        List<Fragment> data = new ArrayList<>();
        data.add(new RecyclerViewFragment());
        data.add(new RecyclerViewFragment());
        data.add(new RecyclerViewFragment());
        return data;
    }
}
